package com.yocard.yxyd.ui.activity;

import android.view.View;
import android.widget.TextView;

import com.yocard.yxyd.ui.dialog.CommonDialog;
import com.yocard.yxyd.utils.util.ActivityUtils;
import com.yocard.yxyd.utils.util.AppUtils;
import com.yocard.yxyd.utils.util.CacheDoubleStaticUtils;
import com.gyf.barlibrary.ImmersionBar;
import com.yocard.yxyd.R;
import com.yocard.yxyd.base.Constants;
import com.yocard.yxyd.ui.activity.base.SimpleActivity;

import butterknife.BindView;
import butterknife.OnClick;
import cn.jpush.android.api.JPushInterface;

/**
 * Created on 2019/4/10.
 * 设置界面 16/05/04
 *
 */
public class SettingActivity extends SimpleActivity {

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_version)
    TextView tvVersion;

    @Override
    protected int getLayout() {
        return R.layout.act_setting;
    }

    @Override
    protected void initEventAndData() {
        initTitle();

        String appVersionName = AppUtils.getAppVersionName();
        tvVersion.setText("V"+appVersionName);
    }

    private void initTitle(){
        ImmersionBar.with(this).statusBarColor(R.color.white)
                .statusBarDarkFont(true).navigationBarColor(R.color.white).init();
        tvTitle.setText("设置");
    }

    @OnClick({R.id.iv_back,R.id.rl_phone,R.id.btn_login_out})
    public void onClick(View view){
        switch (view.getId()){
            case R.id.iv_back:
                ActivityUtils.finishActivity(this);
                break;
            case R.id.rl_phone:
                ActivityUtils.startActivity(VerifyPhoneActivity.class);
                break;
            case R.id.btn_login_out:
                CommonDialog.Builder builder = new CommonDialog.Builder(mContext).setTitle("确认退出该账号？")
                        .setLeftText("取消")
                        .setRightText("确认")
                        .setLogo(R.mipmap.ic_wode_renzheng)
                        .setListener(pos -> {
                            if (pos == CommonDialog.CLICK_POS_RIGHT) {
                                CacheDoubleStaticUtils.remove(Constants.KEY_TOKEN);
                                ActivityUtils.startActivity(LoginActivity.class);
                                JPushInterface.stopPush(this);     		// 暂停 JPush
                            }
                        });
                builder.show();
                break;
        }
    }
}
